package com.example.yigoumall.service;

import com.example.yigoumall.entity.Order;
import com.example.yigoumall.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class OrderService {
    
    @Autowired
    private OrderMapper orderMapper;
    
    public List<Order> findAll() {
        return orderMapper.findAll();
    }
    
    public Order findById(Integer id) {
        return orderMapper.findById(id);
    }
    
    public List<Order> findByUserId(Integer userId) {
        return orderMapper.findByUserId(userId);
    }
    
    public Order save(Order order) {
        if (order.getId() == null) {
            orderMapper.insert(order);
        } else {
            orderMapper.update(order);
        }
        return order;
    }
    
    public void deleteById(Integer id) {
        orderMapper.deleteById(id);
    }
}